<template>
	<view class="localmore">
		<scroll-view scroll-y="true" @scrolltolower="getPetMore" class="scroll-Y">
			<view>
				<card :dataList="datalist" :isDate="true" :isWrap="true" @onclickHandler="clickHandler"></card>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import card from "../../components/carditem/carditem.vue"
	export default {
		data() {
			return {
				datalist: [],
				triggered: false,
				limit: 20,
				stop: false,
			};
		},
		methods: {
			clickHandler(item, index) {
				uni.navigateTo({
					url: '/subpack/localdetail/localdetail?id=' + item._id
				})
			},
			getPet(limit = 20) {
				if (this.stop) return
				wx.cloud.callFunction({
					name: 'logins',
					data: {
						useName: 'getLostPet',
						limit,
					}
				}).then(res => {
					// console.log("getLostPet:", res)
					this.format(res.result.data)
					if (res.result.count < this.limit) {
						this.stop = true
					}
				})
			},
			format(arr) {
				for (let i = 0; i < arr.length; i++) {
					let item = arr[i]
					let img = item.swiperList[0]
					this.datalist.push({
						...item,
						img
					})
				}
				console.log('this.datalist:---- ', this.datalist);
			},
			getPetMore() {
				if(this.stop){
					uni.showToast({
						mask:true,
						icon:"error",
						title:"已无更多数据~"
					})
					return
				}
				this.limit += 20
				console.log("getPetMore:-", this.limit)
				this.getPet(this.limit)
			}
			// onRefresh() {
			// 	if (this._freshing) return;
			// 	this._freshing = true;
			// 	setTimeout(() => {
			// 		this.triggered = false;
			// 		this._freshing = false;
			// 	}, 3000)
			// },

		},
		components: {
			card
		},
		mounted() {
			this.getPet()
			this._freshing = false;
			setTimeout(() => {
				this.triggered = true;
			}, 1000)
		}
	}
</script>

<style lang="scss" scoped>
	.localmore {
		padding: 10upx $uni-spacing-row-base ;
		background-color: $uni-color-yellow-bg;

		// min-height: 100vh;
		// box-sizing: border-box;
		.scroll-Y {
			height: 100vh;
		}
	}
</style>